package com.ayoka.parenting.interf;

import android.util.Log;

import com.ayoka.parenting.base.AppContext;
import com.ayoka.parenting.bean.UserManager;
import com.tencent.ticsdk.core.TICManager;

/**
 * @ProjectName: AyokaCoach.
 * @ClassName: SimpleTICCallback.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/11/29 09:42.
 */

public abstract class SimpleTICCallback implements TICManager.TICCallback {

    @Override
    public void onError(String module, int errCode, String errMsg) {
        if (errCode == 6014) {
            reLogin();
        } else {
            onFailure(errCode, errMsg);
        }
    }

    public abstract void onFailure(int errorCode, String errorMessage);


    // 刷新Token
    public synchronized void reLogin() {
        if (UserManager.getInstance() == null) {
            return;
        }
        final String userId = UserManager.getInstance().uid;
        String userSign = UserManager.getInstance().tim_user_sig;
        TICManager.getInstance().login(userId, userSign, new TICManager.TICCallback() {
            @Override
            public void onSuccess(Object data) {
                Log.d("SimpleTICCallback", "重新登录成功");
                onFailure(6014, "重新登录成功");
            }

            @Override
            public void onError(String module, int errCode, String errMsg) {
                AppContext.reLogin();
            }
        });
    }
}
